﻿using Commen;
using DbF;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AyaWo.SpiderService
{
    public partial class main : Form
    {
        public main()
        {
            InitializeComponent();

            // var va = "server=122.112.229.171;user id=Sp;password=ChinaZ_55512hbCf3tLiEOp;database=ayawoWeb;charset=utf8";
            try
            {
                var va = DatHelper<string>.GetDatStr("connStr.dat");
                var AutoAonnStr = DatHelper<string>.GetDatStr("AutoConnStr.dat");
                textBox1.Text = AutoAonnStr;
                //try
                //{
                //    DbHelper dh = new DbHelper(va, SqlSourceType.MySql);
                //    dh.OpenConnection();
                //    dh.Dispose();
                //}
                //catch
                //{
                //    ConnForm cf = new ConnForm();
                //    //cf.ShowDialog();
                //    Application.Exit();
                //    Application.Run(cf);
                //}
                
            }
            catch (Exception ex)
            {
            }
        }

        /// <summary>
        /// 编辑按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("编辑按钮");
        }

        /// <summary>
        /// 添加按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            AddWebSite aws = new SpiderService.AddWebSite();
            this.Hide();
            if (aws.ShowDialog() == DialogResult.OK)
            {
                this.Show();
            }  
        }

        /// <summary>
        /// 启动服务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 关闭服务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 保存设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 测试连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button9_Click(object sender, EventArgs e)
        {
            string connStr = textBox1.Text.Trim();
            DbHelper dh = new DbHelper(connStr, SqlSourceType.MySql);
            try
            {
                dh.OpenConnection();
                MessageBox.Show("连接字符串正确....");
            }
            catch
            {
                MessageBox.Show("连接字符串错误....");
            }
            finally
            {
                dh.Dispose();
            }
        }
        /// <summary>
        /// 保存连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button8_Click(object sender, EventArgs e)
        {
            try
            {
                string connStr = textBox1.Text.Trim();
                DatHelper<string>.SaveDat("AutoConnStr.dat", connStr);
                MessageBox.Show("保存成功....");
            }
            catch
            {
                MessageBox.Show("保存失败....");
            }
        }

        /// <summary>
        /// 保存更新语句
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        ///退出登陆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button10_Click(object sender, EventArgs e)
        {
           Caches.Remove("userInfo");
            this.Hide();
            LogForm lf = new LogForm();
            if (lf.ShowDialog() == DialogResult.OK)
            {
                this.Show();
            }
        }

    }
}
